package com.qf.ssm.service.impl;

import com.qf.ssm.common.exception.ServiceException;
import com.qf.ssm.common.vo.ResponseCode;
import com.qf.ssm.entity.Store;
import com.qf.ssm.mapper.StoreMapper;
import com.qf.ssm.service.StoreService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author KING
 * @ClassName: com.qf.ssm.service.impl.StoreServiceImpl
 * @Description: 该类的功能描述
 * @date: 2021/10/14 9:07
 */
@Service
public class StoreServiceImpl implements StoreService {
    @Resource
    private StoreMapper storeMapper;

    @Override
    public Boolean isOperate(Long storeId) {
        Integer status = storeMapper.selectStatus(storeId);
        return status == 1;
    }

    /**
     * 停业，同时关闭接单
     *
     * @param storeId
     * @return
     */
    @Override
    public Boolean closeStore(Long storeId) {
        Integer update = null;
        try {
            update = storeMapper.updateStatus(storeId);
        } catch (ServiceException e) {
            throw new ServiceException(ResponseCode.ERROR);
        }
        return update == 1;
    }

    @Override
    public String operateTime(Long storeId) {
        String time = null;
        try {
            Store store = storeMapper.selectOperateTime(storeId);
            time = store.getOnTimeStart() + "-" + store.getOnTimeEnd();
        } catch (ServiceException ex) {
            throw new ServiceException(ResponseCode.ERROR);
        }
        return time;
    }


}
